//
//  ShareCollectionViewCell.m
//  TextApplication
//
//  Created by dllo on 16/8/31.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ShareCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "NetImageSize.h"
#import <AVFoundation/AVFoundation.h>


@interface ShareCollectionViewCell ()<UICollectionViewDelegateFlowLayout>
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;

@property (nonatomic, assign) CGRect picRect;


@end


@implementation ShareCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.picImageView = [[UIImageView alloc] init];

    }
    return self;
}

//- (void)layoutSubviews {
//    [super layoutSubviews];
//   
////    self.picImageView.frame = self.picRect;
//    self.picImageView.center = self.contentView.center;
////    self.picImageView.frame = CGRectMake(0, 0, 50, 50);
//    [self.contentView addSubview:self.picImageView];
//}


-(void)setGoodsM:(GoodsModel *)goodsM
{
    _goodsM = goodsM;
    _urlStr = _goodsM.goods_image;
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:self.urlStr]];
    CGSize size = [NetImageSize downloadImageSizeWithURL:self.urlStr];
    if (size.width != 0 && size.height != 0) {
        
//        if (_goodsM.tempSize.width == 0 && _goodsM.tempSize.height == 0) {
//            
//            _goodsM.tempSize = size;
//            NSLog(@"3333=====%@",NSStringFromCGSize(_goodsM.tempSize));
//            
//        }else
//        {
//            size = _goodsM.tempSize;
//            NSLog(@"0000000000000000000走了=====");
//            
//        }
        
        if (size.width > size.height) {
            self.picRect = AVMakeRectWithAspectRatioInsideRect(size, CGRectMake(0, 0, self.contentView.bounds.size.width, CGFLOAT_MAX));
            NSLog(@"%f", self.picRect.size.width);
                    self.picImageView.frame = self.picRect;
        } else  {
            self.picRect = AVMakeRectWithAspectRatioInsideRect(size, CGRectMake(0, 0, CGFLOAT_MAX, self.contentView.bounds.size.width));
                    self.picImageView.frame = self.picRect;
            //                NSLog(@"%f", self.picRect.size.width);
            
            
        }
        [self.contentView addSubview:self.picImageView];
        self.picImageView.center = self.contentView.center;
    }
}

- (void)setUrlStr:(NSString *)urlStr {
    _urlStr = urlStr;
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:self.urlStr]];
    CGSize size = [NetImageSize downloadImageSizeWithURL:self.urlStr];
     NSLog(@"====size = %@",NSStringFromCGSize(size));
    NSLog(@"====3333 = %@",NSStringFromCGRect(self.picImageView.frame));
    NSLog(@"====frame = %@",NSStringFromCGRect(self.picRect));
}

//- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
//    [super applyLayoutAttributes:layoutAttributes];
////    self.picImageView.frame = self.picRect;
////    self.picImageView.center = self.contentView.center;
//}

//- (void)setPicWidth:(CGFloat)picWidth {
//    _picWidth = picWidth;
//    _width = _picWidth;
//}
//- (void)prepareForReuse {
//    [super prepareForReuse];
////    self.picImageView.image = nil;
//    
//    self.picImageView.frame = self.picRect;
//    self.picImageView.center = self.contentView.center;
//}
//- (void)setPicHeight:(CGFloat)picHeight {
//    _picHeight = picHeight;
//    _height = _picHeight;
//}


@end
